using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessBeans
    {
        [TestFixture]
        public class When_wrapping_a_basic_class_with_a_property : TemplateTestsBase
        {
            private Person _value;

            [SetUp]
            public override void SetUp()
            {
                base.SetUp();
                _value = new Person
                {
                    Name = "Bob"
                };
            }

            [Test]
            public void Assure_the_ToString_method_is_used_by_defalt()
            {
                SetTemplateContent("${message}");
                AddTemplateVariable("message", _value);

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("Person (Name = 'Bob')"));
            }

            [Test]
            public void Assure_the_property_value_is_passed_the_template()
            {
                SetTemplateContent("${message.Name}");
                AddTemplateVariable("message", _value);

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("Bob"));
            }

            [Test]
            public void Assure_the_ToString_return_value_is_passed_the_template()
            {
                SetTemplateContent("${message.ToString()}");
                AddTemplateVariable("message", _value);

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("Person (Name = 'Bob')"));
            }

            public class Person
            {
                public string Name { get; set; }

                public override string ToString()
                {
                    return string.Format("Person (Name = '{0}')", Name);
                }
            }
        }

    }
}
// ReSharper enable InconsistentNaming
